# -*- coding: utf-8 -*-
"""\
cSAXS data preparation script, new flavor.
"""
import sys

first_scan = 103


import ptycho2 as ptycho
import numpy as np

# Need to "hack" the defaults for continuous scans
ptycho.cSAXS.FILENAME_PATTERN = '{read_path}/{prefix}{scan_number:05d}_{index}_00000.{file_extension}'

# Empty parameter structure
p = ptycho.Param()

p.verbose_level = 3
p.interactive = False                         # Not used for now
p.base_path = '/home/philipp/Documents/master'
#p.base_path = '/afs/psi.ch/user/b/braun_p/data03_2013/'
p.user = 'e14332'
#p.scan_number = 300 
p.dpsize = (192,192)                          # Crop size (used to be "asize")
p.ctr = 'inter'#(276, 376)#(309, 263)                               # Center of cropped array
p.motors = ('py', 'px')                      # Motor names in y and x
p.motors_multiplier = 1e-3                    # Multiplier to convert motor values to meters
p.energy = 6.2                                # Energy in keV
p.detector_pixel_size = 75e-6                # Detector pixel size
p.detector_distance = 7.2122                    # Detector distance
p.scan_type = 'custom'#'raster'                            # None (use spec), or 'raster', 'round', 'round_ROI'
p.positions = np.array([[  0.00000000e+00 ,  1.00000000e-09],
 [  4.05000000e-07 ,  7.00000000e-09],
 [  8.17000000e-07 ,  7.00000000e-09],
 [  1.22900000e-06 ,  7.00000000e-09],
 [  1.64100000e-06 ,  7.00000000e-09],
 [  2.05300000e-06 ,  7.00000000e-09],
 [  2.46500000e-06 ,  7.00000000e-09],
 
 
 [  2.80200000e-06 ,  5.08000000e-07],
 [  2.39000000e-06 ,  5.08000000e-07],
 [  1.97800000e-06 ,  5.08000000e-07],
 [  1.56600000e-06 ,  5.08000000e-07],
 [  1.15400000e-06 ,  5.08000000e-07],
 [  7.42000000e-07 ,  5.08000000e-07],
 
 
 [  2.80249000e-23  , 1.00200000e-06],
 [  4.05000000e-07  , 1.00900000e-06],
 [  8.17000000e-07  , 1.00900000e-06],
 [  1.22900000e-06  , 1.00900000e-06],
 [  1.64100000e-06  , 1.00900000e-06],
 [  2.05300000e-06  , 1.00900000e-06],
 [  2.46500000e-06  , 1.00900000e-06],
 
 
 [  2.80200000e-06  , 1.51000000e-06],
 [  2.39000000e-06  , 1.51000000e-06],
 [  1.97800000e-06  , 1.51000000e-06],
 [  1.56600000e-06  , 1.51000000e-06],
 [  1.15400000e-06  , 1.51000000e-06],
 [  7.42000000e-07  , 1.51000000e-06],
 
 
 [  2.80249000e-23  , 2.00400000e-06],
 [  4.05000000e-07  , 2.01100000e-06],
 [  8.17000000e-07  , 2.01100000e-06],
 [  1.22900000e-06  , 2.01100000e-06],
 [  1.64100000e-06  , 2.01100000e-06],
 [  2.05300000e-06  , 2.01100000e-06],
 [  2.46500000e-06  , 2.01100000e-06],
 
 
 [  2.80200000e-06 ,  2.51200000e-06],
 [  2.39000000e-06 ,  2.51200000e-06],
 [  1.97800000e-06 ,  2.51200000e-06],
 [  1.56600000e-06 ,  2.51200000e-06],
 [  1.15400000e-06 ,  2.51200000e-06],
 [  7.42000000e-07 ,  2.51200000e-06],
 
 
 [  2.80249000e-23 ,  3.00600000e-06],
 [  4.05000000e-07 ,  3.01300000e-06],
 [  8.17000000e-07 ,  3.01300000e-06],
 [  1.22900000e-06 ,  3.01300000e-06],
 [  1.64100000e-06 ,  3.01300000e-06],
 [  2.05300000e-06 ,  3.01300000e-06],
 [  2.46500000e-06 ,  3.01300000e-06],
 
 
 [  2.80200000e-06  , 3.51400000e-06],
 [  2.39000000e-06  , 3.51400000e-06],
 [  1.97800000e-06  , 3.51400000e-06],
 [  1.56600000e-06  , 3.51400000e-06],
 [  1.15400000e-06  , 3.51400000e-06],
 [  7.42000000e-07  , 3.51400000e-06],
 [  3.30000000e-07  , 3.51400000e-06],
 [  2.80249000e-23  , 3.59600000e-06]])
p.pilatus_dir = 'eiger'
p.pilatus_mask = p.base_path + '/eiger_valid_mask.mat'
p.isEigerFile = False
#p.scan_params.nx = 200
#p.scan_params.ny = 0
#p.scan_params.step_size_x = .02e-6
#p.scan_params.step_size_y = .5e-6

specinfo = ptycho.cSAXS.spec.SpecInfo(p.base_path + '/specES1/dat-files/specES1_started_2013_03_20_1108.dat')
#specinfo = ptycho.cSAXS.spec.SpecInfo(p.base_path + '/specES1/dat-files/specES1_started_2013_03_16_1319.dat')
#specinfo = ptycho.cSAXS.spec.SpecInfo('/home/philipp/Documents/master/specES1/dat-files/specES1_started_2013_03_16_1319.dat')
p.spec_filename = specinfo

p.scan_number = first_scan
ptycho.cSAXS.prepare_data(p)
